#!/bin/bash

# Linux 部署脚本 - SPI.AgentServer
# 用法：./deploy-to-linux.sh

echo "======================================="
echo "  SPI.AgentServer Linux 部署脚本"
echo "======================================="

# 1. 发布项目（自包含模式，包含运行时）
echo "正在发布项目..."
dotnet publish -c Release -r linux-x64 --self-contained true -p:PublishSingleFile=false -o ./publish/linux-x64

if [ $? -ne 0 ]; then
    echo "❌ 发布失败！"
    exit 1
fi

echo "✅ 发布成功！"
echo ""
echo "发布文件位置: ./publish/linux-x64"
echo ""
echo "======================================="
echo "  后续部署步骤："
echo "======================================="
echo "1. 将 publish/linux-x64 文件夹压缩："
echo "   cd publish && tar -czf agent-server.tar.gz linux-x64/"
echo ""
echo "2. 上传到 Linux 服务器："
echo "   scp agent-server.tar.gz user@server:/opt/"
echo ""
echo "3. 在 Linux 服务器上解压并运行："
echo "   cd /opt"
echo "   tar -xzf agent-server.tar.gz"
echo "   cd linux-x64"
echo "   chmod +x SPI.AgentServer"
echo "   ./SPI.AgentServer"
echo ""
echo "4. 配置为系统服务（可选）："
echo "   sudo cp agent-server.service /etc/systemd/system/"
echo "   sudo systemctl daemon-reload"
echo "   sudo systemctl enable agent-server"
echo "   sudo systemctl start agent-server"
echo "======================================="
